package com.st.controller;

import com.st.base.BaseResult;
import com.st.po.ValidationDelFooPo;
import com.st.pojo.User;
import com.st.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理控制器",description = "所有跟用户相关的操作")
@RestController
@RequestMapping(path = "user")
public class UserController {
    @Resource
    private UserService userService;

    @Operation(hidden = true)
    @RequestMapping(path = "getOneById",method = RequestMethod.GET)
    public BaseResult getOne(@RequestParam("uid") Integer id){
        User user = userService.getById(id);

        return BaseResult.ok(user);
    }


    /*
    普通测试接口
     */
    @Operation(summary = "删除用户",description = "根据用户传如的id删除对应的用户，返回 ok" +
            " 或者 error")
    @Parameters({
            @Parameter(name = "id",description = "用户编号",required = true)
    })
    @RequestMapping(path = "delFoo",method = RequestMethod.DELETE)
    public String delFoo(
            @RequestParam("id") Integer uid
    ){
        //对客户传入的编号进行判断校验
        if(uid > 0){
            boolean remove = userService.removeById(uid);
            return remove ? "ok" : "error";
        }else{
            return "gun";
        }

    }


    /*
    validation测试接口
     */
    @Operation(summary = "validation 测试 删除用户",description = "根据用户传如的id删除对应的用户，返回 ok" +
            " 或者 error")
    @RequestMapping(path = "validationDelFoo",method = RequestMethod.DELETE)
    public String validationDelFoo(@Valid @RequestBody ValidationDelFooPo validationDelFooPo){
        //对客户传入的编号进行判断校验

        boolean remove = userService.removeById(validationDelFooPo.getId());
        return remove ? "ok" : "error";

    }
}
